package com.kehutong.charge.admin;

import com.kehutong.charge.entity.ReceiptTemplates;
import com.kehutong.charge.service.ReceiptTempsService;
import com.kehutong.common.util.Token;
import org.coraframework.authz.HasPermission;
import org.coraframework.inject.Inject;
import org.coraframework.json.JSONObject;
import org.coraframework.mvc.MvcAction;
import org.coraframework.mvc.http.Bean;
import org.coraframework.mvc.http.ReqMapping;
import org.coraframework.mvc.http.result.Result;

/**
 * @program: kht
 * @description: 模板管理
 * @author: jian Ye
 * @create: 2021/8/3
 **/
@MvcAction
@ReqMapping("/admin/pay/charge/bill/receipt/temp")
public class ReceiptTempsController {

    @Inject
    ReceiptTempsService receiptTempsService;


    @ReqMapping("/page")
    @HasPermission("crm:charge:receipt:temp:view")
    public Object page(JSONObject jsonObject) {
        return receiptTempsService.findPage(jsonObject);
    }

    @ReqMapping("/list")
    @HasPermission("crm:charge:receipt:temp:view")
    public Object list(JSONObject jsonObject) {
        return receiptTempsService.findList(jsonObject);
    }


    @Bean(newInstance=true, copy=true)
    @HasPermission("crm:charge:receipt:temp:edit")
    @ReqMapping("/save")
    public Object save(ReceiptTemplates entity, Token token) throws Exception {
        entity.setUpdateName(token.getUsername());
        return receiptTempsService.save(entity);
    }

    @Bean(copy=true)
    @HasPermission("crm:charge:receipt:temp:edit")
    @ReqMapping("/update")
    public Object update(ReceiptTemplates entity) throws Exception {

        return receiptTempsService.update(entity);
    }

    @HasPermission("crm:charge:receipt:temp:edit")
    @ReqMapping("/delete")
    public Object delete(ReceiptTemplates entity) {

        return receiptTempsService.deleteById(entity.getId());
    }

    @ReqMapping("/setStatus")
    @HasPermission("crm:charge:receipt:temp:edit")
    public Object setStatus(ReceiptTemplates entity) throws Exception {
        entity.setStatus(!entity.isStatus());
        receiptTempsService.update(entity);
        return Result.success();
    }

    @ReqMapping("/get")
    public Object get(ReceiptTemplates entity) {
        return Result.success(entity);
    }
}
